/*
 *
 * Copyright (c) 2021
 * User:Dybala
 * File:InterceptorConfig.java
 * Date:2021/11/08 10:45:08
 */

package com.config.common;

import com.config.Interceptor.AuthenticationInterceptor;
import com.config.Interceptor.CorsInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置拦截器
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(get()).addPathPatterns("/**");

        registry.addInterceptor(authenticationInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**");;    // 拦截所有请求，通过判断是否需要登录

    }
    @Bean
    public AuthenticationInterceptor authenticationInterceptor() {
        return new AuthenticationInterceptor();
    }

    @Bean
    public CorsInterceptor get(){
        return new CorsInterceptor();
    }

}
